<%@ Language=VBScript %>
<%Option Explicit%>
<!-- #include file="upload.asp" -->

<%

'//////////////// VERSION MEJORADA DE COMUN ///////////////////

Session.LCID         = 11274
Response.Buffer      = True
Response.Expires     = -1
'Server.ScriptTimeout = 300

Dim PasarNivel
PasarNivel = False

Dim Conexion, Tabla, SQL

'para implementar singletón por tipos en las conexiones
'dim refColCon
'set refColCon = server.createobject("Scripting.Dictionary")

Sub Conectar_sol
	'if not refColCon.exists(db) then
		Set Conexion = Server.CreateObject("ADODB.Connection")
		'Conexion.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & db)
		Conexion.Open("driver={SQL Server}; server=localhost; database=sol; uid=sa; pwd=fer12345")
		'refcolcon.add db, conexion
	'end if
	'set conexion = refcolcon.item(db)
	'if isempty(tabla) then
		Set Tabla = Server.CreateObject("ADODB.Recordset")
	'end if
End Sub

Sub Conectar_gae
	'if not refColCon.exists(db) then
		Set Conexion = Server.CreateObject("ADODB.Connection")
		'Conexion.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & db)
		Conexion.Open("driver={SQL Server}; server=localhost; database=gae; uid=sa; pwd=fer12345")
		'refcolcon.add db, conexion
	'end if
	'set conexion = refcolcon.item(db)
	'if isempty(tabla) then
		Set Tabla = Server.CreateObject("ADODB.Recordset")
	'end if
	
End Sub

Sub Conectar_gaa
		Set Conexion = Server.CreateObject("ADODB.Connection")
		Conexion.Open("driver={SQL Server}; server=localhost; database=gaa; uid=sa; pwd=fer12345")
		Set Tabla = Server.CreateObject("ADODB.Recordset")
End Sub


Sub Desconectar()
	Conexion.Close
	Set Tabla = Nothing
	Set Conexion = Nothing
End Sub

Function EsValidoLogin(texto)
	Dim Patron, oER, Temp
	Temp = False
	If Len(texto) >= 4 And Len(texto) <= 20 Then
		Patron = "^[a-z0-9]+$"
		Set oER = New RegExp
		oER.Pattern = Patron
		oER.IgnoreCase = True
		If oER.Test(texto) Then Temp = True
		Set oER = Nothing
	End If
	EsValidoLogin = Temp
End Function
%>

<script>
function validar_texto(e)
{
tecla = (document.all) ? e.keyCode : e.which;

//Tecla de retroceso para borrar, siempre la permite
if (tecla==8) return true;

// Patron de entrada, en este caso solo acepta letras
patron =/[A-Za-z]/;

tecla_final = String.fromCharCode(tecla);
return patron.test(tecla_final);
}
</script>

<%
Sub MostrarMsg(msg, volver)
%>
	<script language="javascript" type="text/javascript">
		window.alert('<%= msg %>');
		<% If volver Then %>
		history.back();
		<% End If %>
	</script>
<%
End Sub

Function Fecha1(fecha) 'Pasa de dd/mm/aaaa a aaaa-mm-dd
	Dim Temp, sCadena
	sCadena = Year(fecha) & "-" & Month(fecha) & "-" & Day(fecha) & " " & hour(fecha) & ":" & minute(fecha)
	Fecha1 = sCadena
End Function
%>
<!--#Include Virtual="/expedientes/includes_comun/asp/sncode.asp"-->
<% 'ClaveProducto 'Clave de Activación %>
<%
'NOTE - YOU MUST HAVE VBSCRIPT v5.0 INSTALLED ON YOUR WEB SERVER
'	   FOR THIS LIBRARY TO FUNCTION CORRECTLY. YOU CAN OBTAIN IT
'	   FREE FROM MICROSOFT WHEN YOU INSTALL INTERNET EXPLORER 5.0
'	   OR LATER.


' Create the FileUploader
Dim Uploader, File
Set Uploader = New FileUploader

' This starts the upload process
Uploader.Upload()

'******************************************
' Use [FileUploader object].Form to access 
' additional form variables submitted with
' the file upload(s). (used below)
'******************************************
Response.Write "<b>Thank you for your upload " & Uploader.Form("fullname") & "</b><br>"

' Check if any files were uploaded
If Uploader.Files.Count = 0 Then
	Response.Write "File(s) not uploaded."
Else
	' Loop through the uploaded files
	For Each File In Uploader.Files.Items
		
		' Check where the user wants to save the file
		If Uploader.Form("saveto") = "disk" Then
	
			' Save the file
			File.SaveToDisk "C:\inetpub\wwwroot\compartir\expedientes\upload"
			
	
		ElseIf Uploader.Form("saveto") = "database" Then
			
			' Open the table you are saving the file to
			Set RS = Server.CreateObject("ADODB.Recordset")
			RS.Open "MyUploadTable", "CONNECT STRING OR ADO.Connection", 2, 2
			RS.AddNew ' create a new record
			
			RS("filename")    = File.FileName
			RS("filesize")	  = File.FileSize
			RS("contenttype") = File.ContentType
		
			' Save the file to the database
			File.SaveToDatabase RS("filedata")
			
			' Commit the changes and close
			RS.Update
			RS.Close
		End If
		dim url
		' Output the file details to the browser
		Response.Write "File Uploaded: " & File.FileName & "<br>"
		Response.Write "Size: " & File.FileSize & " bytes<br>"
		Response.Write "Type: " & File.ContentType & "<br><br>"
		url = response.Write("/expedientes/upload/" & File.FileName)
		Conectar_gae
			SQL = "UPDATE Expedientes SET UrlArchivo = '/expedientes/upload/"&File.FileName&"' WHERE Id_Expediente = 'FM-05633-D-14'"
			Response.Write(SQL)
			Conexion.Execute(SQL)
		Desconectar
				
	Next
	
End If


%>